package fw.asmx.materialdesign.activity;

import android.annotation.TargetApi;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.readystatesoftware.systembartint.SystemBarTintManager;

import fw.asmx.materialdesign.R;

public class ViewPagerActivity extends AppCompatActivity
{
    private DrawerLayout drawer;
    private NavigationView navigationView;
    private CollapsingToolbarLayout colToolbar = null;
    private Toolbar toolbar;
    private TextView tvCenterTitle;
    private TabLayout tabLayout;
    private ViewPager viewPager;

    private SystemBarTintManager tintManager;

    private boolean isTitleCenter=false;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tool_bar);
        drawer = (DrawerLayout) findViewById(R.id.dl_main_drawer);
        // colToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        tvCenterTitle=(TextView)findViewById(R.id.toolbar_center_title);
        tabLayout = (TabLayout) findViewById(R.id.tabs);
        viewPager = (ViewPager) findViewById(R.id.vp);

        //KitKat's Tint
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT)
        {
            tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setNavigationBarTintEnabled(true);
            tintManager.setTintResource(R.color.notify_bar_color);
        }
        //
    }

    public DrawerLayout getDrawer()
    {
        return drawer;
    }

    public NavigationView getNavigationView()
    {
        return navigationView;
    }

//    public CollapsingToolbarLayout getColToolbar()
//    {
//        return colToolbar;
//    }

    public Toolbar getToolbar()
    {
        return toolbar;
    }

    public TabLayout getTabLayout()
    {
        return tabLayout;
    }

    public ViewPager getViewPager()
    {
        return viewPager;
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    public SystemBarTintManager getTintManager()
    {
        return tintManager;
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    public void setNotifybarTintColor(int clr)
    {
        tintManager.setStatusBarTintColor(clr);
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    public void setNotifybarTintResource(int resId)
    {
        tintManager.setStatusBarTintResource(resId);
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    public void setNotifybarTintDrawable(Drawable drawable)
    {
        tintManager.setStatusBarTintDrawable(drawable);
    }

    public void setToolbarMenu(int id)
    {
        toolbar.inflateMenu(id);
    }

    /**
     * If use CollapsingToolbarLayout,then center title not effect!
     * @param title
     */
    public void setToolbarTitle(CharSequence title)
    {
        tvCenterTitle.setVisibility(View.GONE);
        if (colToolbar != null)
        {
            colToolbar.setTitle(title);
        }
        else
        {
            if(isTitleCenter)
            {
                toolbar.setTitle("");
                tvCenterTitle.setVisibility(View.VISIBLE);
                tvCenterTitle.setText(title);
            }
            else
            {
                tvCenterTitle.setText("");
                toolbar.setTitle(title);
            }
        }
    }
}
